import {abstractValidator} from "./abstractValidator";
import {mc_validatorResult} from "../model/mc_validatorResult";
/**
 * Created by ybjaa on 2017/7/3.
 */

export class equalProperyValidator extends abstractValidator{

    private propery="";

    public setParameters(propery:string): void {
        this.propery=propery;
    }

    protected getValidator(value:string|number,thisObj:Object): mc_validatorResult {

        if(!thisObj){
            this.setResult(false,"对象为空");
            return this.result;
        }

        let equalObj= thisObj[this.propery];

        if(!equalObj||!value){
            this.setResult(false,"比较对象为空");
            return this.result;
        }

        if(typeof (equalObj)!==typeof (value)){
            this.setResult(false,"比较对象类型不相等");
            return this.result;
        }

        if(equalObj!==value){
            this.setResult(false,"比较对象值不相等");
            return this.result;
        }

        return this.result;

    }
}